package com.wt.service.impl;

import java.util.Date;
import java.util.Random;

import javax.annotation.Resource;
import javax.xml.crypto.Data;

import org.springframework.stereotype.Service;

import com.wt.dao.DistributorMapper;
import com.wt.pojo.Distributor;
import com.wt.pojo.Member;
import com.wt.service.WelcomeService;
import com.wt.util.EncryptUtil;

/**
 * Author hiberk
 * Date 2017/6/29 14:40
 */
@Service("WelcomeService")
public class WelcomeServiceImpl implements WelcomeService {
    @Resource
    private DistributorMapper DistributorMapper;

	@Override
	public Distributor login(String phone, String password) {
		// TODO Auto-generated method stub
		String encryPwd = EncryptUtil.getMD5(password);
		Distributor distributor = DistributorMapper.getlogin(phone,encryPwd);
		return distributor;
		
	}
    
	public String getSalt( int length){
		/** 
	     * 生成含有随机盐的密码 
	     */  
		   String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";     
		    Random random = new Random();     
		    StringBuffer sb = new StringBuffer();     
		    for (int i = 0; i < length; i++) {     
		        int number = random.nextInt(base.length());     
		        sb.append(base.charAt(number));     
		    }     
		    return sb.toString(); 
	}

	@Override
	public int register(String account, String pwd, String name, String phone, String identity, String bank_num,
			String bank_addr, String address) {
		// TODO Auto-generated method stub
		
		String encryPwd = EncryptUtil.getMD5(pwd);
		Date date = new Date();
		Integer createTime = (int) (date.getTime()/1000);
		return 	DistributorMapper.register(account, name, phone, identity, bank_num, bank_addr, encryPwd, createTime, address);
	}

	@Override
	public Distributor getDistributorByAccount(String account) {
		// TODO Auto-generated method stub
		return DistributorMapper.getDisributorByAccount(account);
	}
}
